﻿Imports System.Data.OleDb


Public Class Search
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SqlDataSource1.SelectCommand = "SELECT [T_ID], [T_Title], [T_Picture], [T_Text], [T_time], [T_Writer], [T_type] " & _
                                        "FROM [TBL_Topics] WHERE " & _
                                        " ( [T_Text] like ""%" & Request.QueryString("S") & "%"" ) OR " & _
                                        " ( [T_type] like ""%" & Request.QueryString("S") & "%"" ) OR " & _
                                        " ( [T_Title] like ""%" & Request.QueryString("S") & "%"" ) OR " & _
                                        " ( [T_Writer] like ""%" & Request.QueryString("S") & "%"" )  "

        GridView1.DataBind()

        Dim searchby As String

        If User.Identity.Name <> "" Then
            searchby = User.Identity.Name
        Else
            searchby = "Anonymouse"
        End If


        Dim sql As String = "INSERT INTO TBL_SearchPhrases (S_Phrase, UserName) VALUES (@f1,@f2)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)

        cmd.Parameters.AddWithValue("@f1", Request.QueryString("S"))
        cmd.Parameters.AddWithValue("@f2", searchby)

        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()

    End Sub

End Class